import logging
import time
import os

from package.Utils.config import config_obj  # 导入 config_obj 对象(python代码)


output = "./log"
logtime = time.strftime("%Y-%m-%d___%H--%M--%S")

logger = logging.getLogger('Program Name-Version')
logger.setLevel(logging.DEBUG)

formatter = logging.Formatter('%(asctime)s - %(levelname)s - Logger for YJQ : %(message)s')

consoleHeader = logging.StreamHandler()
consoleHeader.setFormatter(formatter)
consoleHeader.setLevel(logging.INFO)

if not os.path.exists(output):
    os.makedirs(output)

fileHandler = logging.FileHandler(f"{output}/{logtime}.log")
fileHandler.setLevel(logging.DEBUG)
fileHandler.setFormatter(formatter)

logger.addHandler(fileHandler)
logger.addHandler(consoleHeader)

class mylogger:
    def __init__(self):
        print(config_obj.config_text)
        self.log_enabled = config_obj.config_text['log_Enable']

mylog = mylogger()